//
// Description: 5954. 给植物浇水 II
// Created by Loading on 2021/12/12.
//

#include <bits/stdc++.h>

using namespace std;

int minimumRefill(vector<int> &plants, int capacityA, int capacityB) {
    int res = 0;
    int cA = capacityA;
    int cB = capacityB;
    int n = plants.size();
    // 直接模拟
    int i = 0, j = n - 1;
    for (; i < j; i++, j--) {
        if (cA < plants[i]) {
            cA = capacityA;
            res++;
        }
        if (cB < plants[j]) {
            cB = capacityB;
            res++;
        }
        cA -= plants[i];
        cB -= plants[j];
    }
    if (i == j) {
        if (plants[i] > cA && plants[i] > cB) {
            ++res;
        }
    }

    return res;
}

int main() {
    vector<int> plants = {1, 2, 4, 4, 5};
    int capacityA = 6;
    int capacityB = 5;
    int res = minimumRefill(plants, capacityA, capacityB);
    cout << res << endl;

    return 0;
}